package com.ccloud.common.mybatisplus.base.warpper;

import java.util.List;
import java.util.Map;

/**
 * @version V1.0
 * @Project：web-spring-boot-starter
 * @Title：BaseControllerWarpper.java
 * @Description：控制器查询结果的包装类基类
 * @Package com.ztyt.web.core.page.warpper
 * @author：xiehao
 * @date：2019年07月01日
 * @Copyright: 武汉中天云通数据科技有限责任公司  All rights reserved.
 */
public abstract class BaseControllerWrapper {

    public Object obj = null;

    public BaseControllerWrapper() {

    }

    public BaseControllerWrapper(Object obj) {
        this.obj = obj;
    }

    @SuppressWarnings("unchecked")
    public Object warp() {
        if (this.obj instanceof List) {
            List<Map<String, Object>> list = (List<Map<String, Object>>) this.obj;
            for (Map<String, Object> map : list) {
                warpTheMap(map);
            }
            return list;
        } else if (this.obj instanceof Map) {
            Map<String, Object> map = (Map<String, Object>) this.obj;
            warpTheMap(map);
            return map;
        } else {
            return this.obj;
        }
    }

    protected abstract void warpTheMap(Map<String, Object> map);
}
